<?php


namespace App\Modules\Health\Extensions\Tools;


use App\Modules\Health\Models\Disease;
use Dcat\Admin\Grid\BatchAction;
use Illuminate\Http\Request;

class BatchChangeDiseaseStatus extends BatchAction
{
    protected $action;
    protected $style = 'btn btn-white waves-effect';

    public function __construct($title = null, $action = 1)
    {
        $this->title = $title;
        $this->action = $action;
    }

    public function confirm()
    {
        return $this->action == 1 ? '是否批量修改为显示？' : '是否批量修改为隐藏？';
    }

    public function handle(Request $request)
    {
        $keys = $this->getKey();

        $action = $request->get('action');

        Disease::whereIn('id', $keys)->update([
            'is_show' => $action
        ]);

        return $this->response()->success('操作成功')->refresh();
    }

    public function parameters()
    {
        return [
            'action' => $this->action,
        ];
    }
}
